import java.util.ArrayList;
import java.util.List;

public class Solution234 {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }


    public boolean isPalindrome(ListNode head) {
        List<Integer> list=new ArrayList<>();
        while (head!=null){
            list.add(head.val);
            head=head.next;
        }
        for (int l=0,r=list.size()-1;l<r;l++,r--){
            if (list.get(l)!=list.get(r)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution234().isPalindrome(new ListNode(1,new ListNode(2,new ListNode(2,new ListNode(1))))));
    }
}
